<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<div id="page-content">
    <div class="row">

        <div class="col-lg-12">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">工作日志</h3>
                </div>
                <div class="panel-body">
                    <div class="form-inline">
                        <div class="row">
                            <div class="col-sm-6 table-toolbar-left">
                                <btn id="btn_add_worklog" class="btn btn-primary btn-sm">
                                    <i class="ti-plus"> </i> 新建工作日志登记表
                                </btn>
                            </div>
                            <div class="col-sm-6 table-toolbar-right">
                                <span id="spanCatalog" style="display: none">1</span>
                                <div class="btn-group right">
                                    <button id="btnAllWorklogs" class="btn btn-default">所有工作日志</button>
                                    <button id="btnMyWorklogs" class="btn btn-success">我的工作日志</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table id="worklog_running_table"></table>
                        <div id="worklog_running_page"></div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

<script>

    $(function(){

        init_grid_worklog();

    });

    function init_grid_worklog() {

        __init_jqgrid('worklog_running_table', 'worklog_running_page',
                '<%=path%>/activiti/worklog/list?catalog=' + $("#spanCatalog").text(),
                ['年份', '月份', '日志名称', '上传日期', '申请人', '文档状态', '操作', 'id'],
                [
                    {name: 'year', index: 'year', width: 40, sortable: true, search: false},
                    {name: 'month', index: 'month', width: 40, sortable: true, search: false},
                    {name: 'name', index: 'name', sortable: false, stype: 'text', searchoptions: {sopt: ['cn']}},
                    {name: 'dateApply', index: 'dateApply', width: 80, sortable: false, search: false},
                    {name: 'creater', index: 'creater', width: 80, sortable: false, search: false},
                    {name: 'processStateName', index: 'processStateName', width: 40, sortable: false, search: false},
                    {name: 'act', index: 'act', width: 150, fixed: true, sortable: false, search: false, formatter: actFormat},
                    {name: 'id', index: 'id', width: 100, key: true, hidden: true, hidedlg: true}
                ],
                true,
                {
                    postData: {catalog: 0x01}
                }
        );

    }
    
    function actFormat(cellvalue, options, rowObject){
        var id = rowObject.id;
        cellvalue = '<button class="btn btn-white btn-sm" data-original-title="查看" onclick="fn_worklog_read(\'' + id + '\');"><i class="fa fa-eye"> </i> 查看</button>';

        return cellvalue;
    }

    function fn_worklog_read(id) {
        loadURL('<%=path%>/activiti/worklog/read/'+id, $('#page-content'));
    }

    $("#btn_add_worklog").click(function(){
        loadURL('<%=path%>/activiti/worklog/create', $('#page-content'));
    });

    $("#btnMyWorklogs").click(function(){
        $("#spanCatalog").text("1");
        $(this).removeClass("btn-default").addClass("btn-success");
        $("#btnAllWorklogs").removeClass("btn-success").addClass("btn-default");
        $("#worklog_running_table").jqGrid('setGridParam', {
            url : '<%=path%>/activiti/worklog/list?catalog=1'
        }).trigger("reloadGrid");
    });

    $("#btnAllWorklogs").click(function(){
        $("#spanCatalog").text("2");
        $(this).removeClass("btn-default").addClass("btn-success");
        $("#btnMyWorklogs").removeClass("btn-success").addClass("btn-default");
        $("#worklog_running_table").jqGrid('setGridParam', {
            url : '<%=path%>/activiti/worklog/list?catalog=2'
        }).trigger("reloadGrid");
    });
</script>